<template>
    <template v-if="item.title">
        <el-sub-menu :index="item.path" :key="item.path" v-if="item?.children?.length > 0">
            <template #title>
                <el-icon>
                    <component :is="item.icon" />
                </el-icon>
                <span>{{ item.title }}</span>
            </template>
            <menuItem v-for="child in item.children" :item="child" :key="child.path" />
        </el-sub-menu>
        <el-menu-item v-else :index="item.path" @click="addTag(item)">
            <el-icon>
                <component :is="item.icon" />
            </el-icon>
            <template #title>
                <span>{{ item.title }}</span>
            </template>
        </el-menu-item>
    </template>
</template>
<script setup name="menuItem">
import { getCurrentInstance } from 'vue' 
import { useTagStore } from "@/store/tagStore";
import { useIsCollapseStore } from "@/store/isCollapseStore";
import VueEvent from '@/utils/event.js'

const isCollapseStore = useIsCollapseStore()
const tagStore = useTagStore()
const { proxy } = getCurrentInstance();
const props = defineProps({
    item: {
        type: Object,
        default: () => { },
    },
})
const addTag = (tag) => {
    tagStore.addTag(tag)
    VueEvent.emit("addTag", tag)
    if (proxy.$isMobile()) {
        isCollapseStore.isCollapse = false
    }
}
</script>
<style lang='less' scoped>
span {
    font-weight: 500;
}
</style>